import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;

@WebServlet("/refresh")
public class refreshServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html; charset = utf8");
        //设置Refresh, 第二个参数表示刷新频率, 单位是秒, 每隔 1s 刷新一次
        resp.setHeader("Refresh", "1");
        //响应                                获取毫秒级别的时间戳
        // resp.getWriter().write("时间戳：" + System.currentTimeMillis());
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        resp.getWriter().write("格式化时间戳 = " + format.format(System.currentTimeMillis()));
    }
}
